﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Booking_Hotel.DBML;

namespace Booking_Hotel.DAL
{
    public class SupplierDAO
    {
        ThanhBHotelDataContext sdb = new ThanhBHotelDataContext();

        public Supplier GetSupplierByID(int supplerID)
        {
            return sdb.sp_SupplierSelect(supplerID).SingleOrDefault();
        }

        public void addSupplier(Supplier supplier)
        {
            Supplier addSupplier = new Supplier
            {
              
                UserName = supplier.UserName,
	            Password = supplier.Password,
	            TenKinhDoanh = supplier.TenKinhDoanh,
	            TenDaiDien = supplier.TenDaiDien,
	            DiaChi = supplier.DiaChi,
	            Mobile = supplier.Mobile,
	            DienThoaiBan = supplier.DienThoaiBan, 

            };
            sdb.Suppliers.InsertOnSubmit(addSupplier);
            sdb.SubmitChanges();
        }

        public void updateSupplier(Supplier supplier)
        {
            Supplier updateSupplier = sdb.Suppliers.Single(ca => ca.SupplierID == (int)supplier.SupplierID);
            {
                updateSupplier.UserName = supplier.UserName;
                updateSupplier.Password = supplier.Password;
                updateSupplier.TenKinhDoanh = supplier.TenKinhDoanh;
                updateSupplier.TenDaiDien = supplier.TenDaiDien;
                updateSupplier.DiaChi = supplier.DiaChi;
                updateSupplier.Mobile = supplier.Mobile;
                updateSupplier.DienThoaiBan = supplier.DienThoaiBan;
            }
            sdb.SubmitChanges();
        }

        public void SupplierActive(Supplier supplier)
        {
            Supplier ActiveSupplier = sdb.Suppliers.Single(ca => ca.UserName == supplier.UserName);
            {
                ActiveSupplier.UserName = supplier.UserName;
                ActiveSupplier.SupplierLevel = supplier.SupplierLevel;
                ActiveSupplier.NgayActive = supplier.NgayActive;
                ActiveSupplier.Active = supplier.Active;
                
            }
            sdb.SubmitChanges();
        }
    }
}